<%@page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8" %>
<%@page import="java.util.Vector"%>
<%@page import="com.reachol.process.mail.CreateUserMailer"%>
<%@page import="com.reachol.objects.Users"%>
<%@page import="com.sun.jimi.core.encoder.jpg.util"%>
<%@page import="com.jimet.security.MD5"%>
<%@page import="com.reachol.objects.User"%>
<%@page import="java.sql.Timestamp"%>
<%@page import="java.util.Date"%>
<%@page import="com.jimet.server.JimetConfiguration" %>

<%
	String fullname = request.getParameter("name");
	String mail = request.getParameter("mail");
	String password = request.getParameter("password");
	Timestamp now = new Timestamp(new Date().getTime());
	String passwordMD5 = MD5.hash(password);

	Users users = new Users();
	users.load("ASC", "id");
	int mailControlFlag = 1; 
	while (users.next()) {
		User tmpObj = (User) users.getNext();
		String controlMail = tmpObj.getMail();
		if (mail.equals(controlMail)) 
		{
			mailControlFlag = 0; //veritabanında aynı kayıt varsa 0 döndürür
			break;
			
		} 
		else
			mailControlFlag = 1;

	}

	if (mailControlFlag == 1) {
		long rid=-1;
		User record = new User();
		String activationCode = MD5.getRandomPassword(12);
		record.setFullname(fullname);
		record.setMail(mail);
		record.setStep(1);
		record.setPassword(passwordMD5);
		record.setTsUpdate(now);
		record.setActivationcode(activationCode);
		rid=record.store();
		session.setAttribute("userId", rid+"");
		//activationCodeString actLink					= JimetConfiguration.getString("APPLICATION.URL")+"dashboard.jsp?actc="+activationCode+"&cid="+rid;
		CreateUserMailer mailProc		= new CreateUserMailer();
		Vector<String> valuesVect		= new Vector<String>();
		valuesVect.add(record.getMail());
		valuesVect.add(record.getFullname());
		valuesVect.add(activationCode);
		valuesVect.add(record.getFullname());
		valuesVect.add(password);
		mailProc.sendMail( valuesVect );
		
	}
%>
<%=mailControlFlag%>